var AjaxCrud = QualityCheck.AjaxCRUD;
var serverUrl = QualityCheck.GPUD.ServiceConfig;
$(function(){
	initSmPages();
	window.onresize = function () {
		initSmPages();
	};
	pagebtns();
	getTeacherCode();
});
function getTeacherCode(){
	var userKey = $("#user-name",parent.document).attr("key");
	var cellphone = $("#user-name",parent.document).attr("code");
	var data = {
			cmd:"getTeacher",
			model:"teacher",
			userKey:userKey,
			data:{
				cellphone:cellphone
			},
			remark:"",
	};
	AjaxCrud.get(serverUrl.ServerLoginUrl,data,function(cres){
		if(cres.result == 1 && cres.data != undefined){
			var teachercode = cres.data.teachercode;
			var classcode = cres.data.classcode;
			$("#user-name",parent.document).attr("teachercode",teachercode).attr("classcode",classcode);
			var data = {
					cmd:"getAllClasses",
					model:"teacher",
					userKey:userKey,
					data:{
						teachercode:teachercode
					},
					remark:""
			};
			AjaxCrud.get2(serverUrl.ServerLoginUrl,data,function(res){
				if(res.result == 1 && res.data != undefined && res.data != ""){
					var contents = "";
					var list = res.data;
					for(var i = 0; i < list.length; i++){
						if(i == 0){
							contents += "<div class='classes-choice classes-choice-select' classcode='"+list[i].classcode+"'>"+list[i].name+"</div>";
						}else{
							contents += "<div class='classes-choice' classcode='"+list[i].classcode+"'>"+list[i].name+"</div>";
						}
					}
					$(".dialog-classes-contents").empty();
					$(".dialog-classes-contents").append(contents);
					changePage(PageUrl.tnewsUrl);
					$(".classes-choice").unbind("click");
					$(".classes-choice").click(function(){
						$(".classes-choice").removeClass("classes-choice-select");
						$(this).addClass("classes-choice-select");
					});
				}else{
					$(".dialog-classes-contents").empty();
					$(".dialog-classes-contents").append("<div class='classes-choice classes-choice-select'>没有相关信息</div>");
					changePage(PageUrl.tnewsUrl);
				}
			},null,null);
		}
	},null,null);
}
function pagebtns(){
	$(".left-menu").click(function(){
		$(".left-menu-sec").hide();
		if($(this).attr("model") == "新闻公告"){
			$("#news-op").show();
			var Hei = $("#news-op .menu-sec").length * $(".menu-sec").height();
			$("#news-op").height(Hei);
		}
	});
	$(".menu-sec").click(function(){
		var model = $(this).attr("title");
		$(".menu-sec").removeClass("menu-sec-select");
		$(this).addClass("menu-sec-select");
		if(model == "新闻公告"){
			changePage(PageUrl.tnewsUrl);
		}else if(model == "班内通知"){
			changePage(PageUrl.addTnewsUrl);
		}else if(model == "教师消息"){
			changePage(PageUrl.addTeamesUrl);
		}else if(model == "学生通知"){
			changePage(PageUrl.addStudentNewsUrl);
		}
	});
}
function changePage(pageUrl){
	$("#right-iframe").attr("src",pageUrl);
}
function initSmPages(){
	var bodyRW = $(".index-body",parent.document).width() - $(".body-left").width()-6;
	$(".body-right").width(bodyRW);
	
	var leftCH = $(".body-left").height() - $(".left-title").height()-1;
	$(".left-content").height(leftCH);
}